package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.framework.utils.ObjectCastUtil;
import com.molichuxing.services.infrastructure.bean.ContractLogBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.ContractLogMapper;
import com.molichuxing.services.infrastructure.dto.response.ContractLogDto;
import com.molichuxing.services.infrastructure.service.ContractLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 合同创建日志表 服务实现类
 * </p>
 *
 * @author zhaopenghui
 * @since 2019-09-11
 */
@Service("contractLogService")
public class ContractLogServiceImpl implements ContractLogService {

    @Autowired
    private ContractLogMapper contractLogMapper;


    @Override
    public Paged<ContractLogDto> getOrderDealerList(Map<String, Object> params, Integer pageNum, Integer pageSize) {

        if(null != params.get("startTime")){
            params.put("startTime", ObjectCastUtil.getDayStart(params.get("startTime")));
        }
        if(null != params.get("endTime")){
            params.put("endTime",ObjectCastUtil.getDayEnd(params.get("endTime")));
        }
        int count = contractLogMapper.getContractLogCount(params);
        if(count <= 0) {
            return new Paged<>(null,0,pageSize);
        }
        List<ContractLogBean> list = contractLogMapper.getContractLogList(params, pageNum, pageSize);
        Paged<ContractLogDto> orderDealerDtoPage = new Paged<>(Convert.toContractLogDto(list), count, pageSize);
        return orderDealerDtoPage;
    }

    @Override
    public Boolean createContractLog(ContractLogDto contractLogDto) {
        int result = contractLogMapper.create(Convert.toContractLogBean(contractLogDto));
        if (result > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Boolean createContractLogList(List<ContractLogDto> contractLogDtoList) {
        int result = contractLogMapper.createContractLogList(Convert.toContractLogBean(contractLogDtoList));
        if (result > 0) {
            return true;
        } else {
            return false;
        }
    }
}
